﻿using Modules;
using AutoMapper;
using PmSoft;
using Modules.Project;

namespace ManagementApi.Models.Project;

public class ProjectLockLogDto : ProjectLockLog
{
    #region 扩展属性

    public int Month { get; set; }
    public string ProjectName { get; set; }
    public string AuditStatusName { get; set; }

    public string AuditIdeaName { get; set; }

    public string LockPrjStatusName { get; set; }

    public string PrjStatusName { get; set; }

    #endregion 扩展属性
}

public static partial class ProjectLockLogExceptions
{
    public static ProjectLockLogDto AsDto(this ProjectLockLog entity)
    {
        ProjectLockLogDto dto = new();
        var mapper = ServiceAccessor.GetService<IMapper>();
        mapper.Map(entity, dto);

        #region 扩展属性赋值

        var projectService = ServiceAccessor.GetService<ProjectService>();
        var project = projectService.GetProjectInfo(entity.ProjectId);
        dto.ProjectName = project?.Name ?? string.Empty;
        dto.Month = entity.LockMonth;
        dto.AuditStatusName = entity.AuditStatus?.GetDescription() ?? string.Empty;
        dto.AuditIdeaName = entity.AuditIdea?.GetDescription() ?? string.Empty;
        if (entity.LockPrjStatus.HasValue)
            dto.LockPrjStatusName = entity.LockPrjStatus.Value.GetDescription();
        if (project != null && project.PrjStatus.HasValue)
            dto.PrjStatusName = project.PrjStatus.Value.GetDescription();

        #endregion 扩展属性赋值

        return dto;
    }
}